# Copyright (C) 2024 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause

qt_policy(SET QTP0001 NEW)

include(GenerateExportHeader)

qt_add_library(tst_qmltyperegistrar_namespaced STATIC
    namespaced.cpp namespaced.h
)

qt_autogen_tools_initial_setup(tst_qmltyperegistrar_namespaced)
qt_enable_autogen_tool(tst_qmltyperegistrar_namespaced "moc" ON)
generate_export_header(tst_qmltyperegistrar_namespaced)
target_include_directories(tst_qmltyperegistrar_namespaced
    PRIVATE
        ${CMAKE_CURRENT_BINARY_DIR} # find autogenerated header
)

target_link_libraries(tst_qmltyperegistrar_namespaced
    PRIVATE
        Qt::Core
        Qt::QmlIntegration
)

qt_add_library(tst_qmltyperegistrar_namespaced_module)
qt_autogen_tools_initial_setup(tst_qmltyperegistrar_namespaced_module)
qt_enable_autogen_tool(tst_qmltyperegistrar_namespaced_module "moc" ON)
qt_add_qml_module(tst_qmltyperegistrar_namespaced_module
    URI Namespaced
    NAMESPACE nnn
    RESOURCE_PREFIX "/"
)

qt_autogen_tools_initial_setup(tst_qmltyperegistrar_namespaced_moduleplugin)

target_include_directories(tst_qmltyperegistrar_namespaced_module
    PRIVATE
        ${CMAKE_CURRENT_BINARY_DIR} # find autogenerated header
)

target_link_libraries(tst_qmltyperegistrar_namespaced_module
    PRIVATE
        tst_qmltyperegistrar_namespaced
)

qt_generate_foreign_qml_types(
    tst_qmltyperegistrar_namespaced
    tst_qmltyperegistrar_namespaced_module
)

# Make sure the backing library is found on Windows next to the executable
set_target_properties(
    tst_qmltyperegistrar_namespaced_module
    PROPERTIES
        RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..
        LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..
        ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..
)
